#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author:Taotie Ren
# import logging 
# 禁用日志模块
# logging.disable(logging.CRITICAL)
# logging.basicConfig(level=logging.DEBUG, format=' %(asctime)s - %(levelname)s - %(message)s')

# combinePdfs.py - Combines all the PDFs in the current working directory into into a single PDF.(Path : PyPDF)

import PyPDF2, os

# Get all the PDF filenames.
pdfFiles = []
for filename in os.listdir('.\\PyPDF\\'):
	if filename.endswith('.pdf'):
		pdfFiles.append(filename)
pdfFiles.sort()

pdfWriter = PyPDF2.PdfFileWriter()

# Loop through all the PDF files.
for filename in pdfFiles:
	pdfFilesObj = open(filename, 'rb')
	pdfReader = PyPDF2.PdfFileReader(pdfFilesObj)

	# Loop through all the pages (except the first) and add them.
	for pageNum in range(1, pdfReader.numPages):
		pageObj = pdfReader.getPage(pageNum)
		pdfWriter.addPage(pageObj)

# Save the resulting PDF to a file.
pdfOutput = open('.\\PyPDF\\allminutes.pdf', 'wb')
pdfWriter.write(pdfOutput)
pdfOutput.close()
